home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / world-wars.swf / scripts / __Packages / classes / Map.as < prev   
Encoding:
Text File  |  2011-09-19  |  27.8 KB  |  864 lines

  1. class classes.Map
  2. {
  3.    var ROOT_MC;
  4.    var GAME_CLASS;
  5.    var HEX;
  6.    var cos30;
  7.    var cos60;
  8.    var sin60;
  9.    var rubbish_arr;
  10.    var CHOSEN_TERR_A;
  11.    var CHOSEN_TERR_B;
  12.    var TERRITORIES_ARR;
  13.    var MAP_ARR;
  14.    var counter;
  15.    var _territory;
  16.    var TERR_A_NArr;
  17.    var TERRITORY_SIZE_min = 17;
  18.    var TERRITORY_SIZE_max = 28;
  19.    var BORDER_COLOR = 4143636;
  20.    var BORDER_ACTIVE_COLOR = 16777215;
  21.    var BORDER_OVER_COLOR = 13421772;
  22.    var BORDER_SIZE = 2;
  23.    var AV_UNITS_PER_TERRITORY = 3;
  24.    var COLOR_ARR = [11304249,7041575,4541257,10439479,5801101,7419137,8092812,4866561];
  25.    function Map(rmc, gc)
  26.    {
  27.       this.ROOT_MC = rmc;
  28.       this.GAME_CLASS = gc;
  29.       this.HEX = new classes.models.Hex();
  30.       this.cos30 = Math.cos(this.deg2rad(30));
  31.       this.cos60 = Math.cos(this.deg2rad(60));
  32.       this.sin60 = Math.sin(this.deg2rad(60));
  33.    }
  34.    function createMap(players)
  35.    {
  36.       var _loc23_ = 34;
  37.       var _loc24_ = 29;
  38.       var _loc27_ = 30;
  39.       var _loc28_ = 34;
  40.       var _loc26_ = this.random2(_loc28_ - _loc27_) + _loc27_;
  41.       if(this.rubbish_arr.length > 0)
  42.       {
  43.          this.clearAll();
  44.       }
  45.       this.rubbish_arr = new Array();
  46.       this.CHOSEN_TERR_A = this.CHOSEN_TERR_B = undefined;
  47.       this.TERRITORIES_ARR = new Array();
  48.       this.MAP_ARR = new Array();
  49.       this.counter = 0;
  50.       this.drawGrid(_loc23_,_loc24_);
  51.       while(this.TERRITORIES_ARR.length < _loc26_)
  52.       {
  53.          var _loc10_ = undefined;
  54.          var _loc9_ = undefined;
  55.          if(this.TERRITORIES_ARR.length == 0)
  56.          {
  57.             var _loc13_ = Math.round((_loc23_ - 1) / 2);
  58.             var _loc12_ = Math.round((_loc24_ - 1) / 2);
  59.             _loc10_ = Math.round(0.25 * _loc13_ + this.random2(0.5 * _loc13_));
  60.             _loc9_ = Math.round(0.25 * _loc12_ + this.random2(0.5 * _loc12_));
  61.          }
  62.          else
  63.          {
  64.             var _loc8_ = false;
  65.             while(!_loc8_)
  66.             {
  67.                var _loc5_ = this.random2(this.TERRITORIES_ARR.length - 1);
  68.                var _loc6_ = this.TERRITORIES_ARR[_loc5_].arr.length - 1;
  69.                while(_loc6_ >= 0)
  70.                {
  71.                   var _loc3_ = this.freeNeighboursArr2(this.TERRITORIES_ARR[_loc5_].arr[_loc6_]);
  72.                   if(_loc3_.length > 0)
  73.                   {
  74.                      var _loc4_ = this.random2(_loc3_.length - 1);
  75.                      _loc10_ = _loc3_[_loc4_].x;
  76.                      _loc9_ = _loc3_[_loc4_].y;
  77.                      _loc8_ = true;
  78.                   }
  79.                   _loc6_ = _loc6_ - 1;
  80.                }
  81.             }
  82.          }
  83.          var _loc7_ = this.newTerritory(_loc10_,_loc9_);
  84.          if(_loc7_.length > 0)
  85.          {
  86.             var _loc11_ = {status:0,player:0,border:undefined,army:0,unitsMC:undefined,unitsNO:0,arr:_loc7_};
  87.             _loc6_ = 0;
  88.             while(_loc6_ < _loc7_.length)
  89.             {
  90.                _loc7_[_loc6_]._territory = _loc11_;
  91.                _loc6_ = _loc6_ + 1;
  92.             }
  93.             this.TERRITORIES_ARR.push(_loc11_);
  94.          }
  95.       }
  96.       var _loc25_ = _root.ARMY;
  97.       var _loc15_ = new Array();
  98.       _loc6_ = 0;
  99.       while(_loc6_ < players)
  100.       {
  101.          _loc15_.push((_loc6_ + _loc25_ - 1) % 3 + 1);
  102.          _loc6_ = _loc6_ + 1;
  103.       }
  104.       _loc6_ = 0;
  105.       while(_loc6_ < this.TERRITORIES_ARR.length)
  106.       {
  107.          this.makeBorder(this.TERRITORIES_ARR[_loc6_],this.HEX.HEIGHT / 2);
  108.          this.markTerritory(this.TERRITORIES_ARR[_loc6_],players - _loc6_ % players,0);
  109.          this.TERRITORIES_ARR[_loc6_].army = _loc15_[this.TERRITORIES_ARR[_loc6_].player - 1];
  110.          _loc6_ = _loc6_ + 1;
  111.       }
  112.       this.randomUnits(players);
  113.    }
  114.    function startInterface()
  115.    {
  116.       this.selectA();
  117.    }
  118.    function markTerritory(terrObj, pl, stat)
  119.    {
  120.       var _loc2_ = 0;
  121.       while(_loc2_ < terrObj.arr.length)
  122.       {
  123.          terrObj.arr[_loc2_]._visible = true;
  124.          terrObj.arr[_loc2_].gotoAndStop(pl);
  125.          _loc2_ = _loc2_ + 1;
  126.       }
  127.       this.colorMC(terrObj.border,this.BORDER_COLOR);
  128.       terrObj.status = stat;
  129.       terrObj.player = pl;
  130.    }
  131.    function drawGrid(w, h)
  132.    {
  133.       var _loc11_ = this.HEX.WIDTH;
  134.       var _loc7_ = 0;
  135.       while(_loc7_ < h)
  136.       {
  137.          var _loc8_ = new Array();
  138.          var _loc6_ = 0;
  139.          while(_loc6_ < w)
  140.          {
  141.             var _loc5_ = this.ROOT_MC.attachMovie("HEX","hex_" + _loc6_ + "x" + _loc7_,this.counter++);
  142.             _loc5_._x = _loc6_ * this.HEX.WIDTH + _loc7_ % 2 * (this.HEX.WIDTH / 2);
  143.             _loc5_._y = _loc7_ * (this.HEX.HEIGHT / 2) * 1.5;
  144.             _loc8_.push(_loc5_);
  145.             _loc5_.x = _loc6_;
  146.             _loc5_.y = _loc7_;
  147.             _loc5_._inTerritory = false;
  148.             _loc5_._onBorder = false;
  149.             _loc5_._visible = false;
  150.             this.rubbish_arr.push(_loc5_);
  151.             _loc6_ = _loc6_ + 1;
  152.          }
  153.          this.MAP_ARR.push(_loc8_);
  154.          _loc7_ = _loc7_ + 1;
  155.       }
  156.       var _loc3_ = 0;
  157.       while(_loc3_ < h)
  158.       {
  159.          var _loc2_ = 0;
  160.          while(_loc2_ < w)
  161.          {
  162.             var _loc4_ = this.MAP_ARR[_loc3_][_loc2_];
  163.             _loc4_.L = this.MAP_ARR[_loc3_][_loc2_ - 1];
  164.             _loc4_.R = this.MAP_ARR[_loc3_][_loc2_ + 1];
  165.             if(_loc3_ % 2 == 0)
  166.             {
  167.                _loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_ - 1];
  168.                _loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_];
  169.                _loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_ - 1];
  170.                _loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_];
  171.             }
  172.             else
  173.             {
  174.                _loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_];
  175.                _loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_ + 1];
  176.                _loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_];
  177.                _loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_ + 1];
  178.             }
  179.             _loc2_ = _loc2_ + 1;
  180.          }
  181.          _loc3_ = _loc3_ + 1;
  182.       }
  183.    }
  184.    function newTerritory(x, y)
  185.    {
  186.       var _loc2_ = new Array(this.MAP_ARR[y][x]);
  187.       this.MAP_ARR[y][x]._inTerritory = true;
  188.       var _loc8_ = this.random2(Math.round(this.TERRITORY_SIZE_max - this.TERRITORY_SIZE_min)) + this.TERRITORY_SIZE_min;
  189.       var _loc7_ = false;
  190.       while(_loc2_.length < _loc8_ && !_loc7_)
  191.       {
  192.          var _loc6_ = 0;
  193.          _loc2_ = this.shuffledArray(_loc2_);
  194.          var _loc3_ = 0;
  195.          while(_loc3_ < _loc2_.length)
  196.          {
  197.             var _loc4_ = this.freeNeighboursArr2(_loc2_[_loc3_]);
  198.             if(_loc4_.length > 0)
  199.             {
  200.                var _loc5_ = _loc4_[this.random2(_loc4_.length - 1)];
  201.                _loc2_.push(_loc5_);
  202.                _loc5_._inTerritory = true;
  203.                _loc3_ = _loc2_.length + 10;
  204.             }
  205.             else
  206.             {
  207.                _loc6_ = _loc6_ + 1;
  208.             }
  209.             _loc3_ = _loc3_ + 1;
  210.          }
  211.          if(_loc6_ >= _loc2_.length)
  212.          {
  213.             _loc7_ = true;
  214.          }
  215.       }
  216.       if(_loc7_)
  217.       {
  218.          if(_loc2_.length >= this.TERRITORY_SIZE_min)
  219.          {
  220.             return _loc2_;
  221.          }
  222.          this.burnTerritory(_loc2_);
  223.          return new Array();
  224.       }
  225.       return _loc2_;
  226.    }
  227.    function neighbourTerritoriesNo(terrArr)
  228.    {
  229.       var _loc6_ = new Array();
  230.       var _loc7_ = 0;
  231.       while(_loc7_ < terrArr.length)
  232.       {
  233.          var _loc5_ = terrArr[_loc7_];
  234.          var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
  235.          var _loc1_ = 0;
  236.          while(_loc1_ < _loc3_.length)
  237.          {
  238.             if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
  239.             {
  240.                var _loc4_ = false;
  241.                var _loc2_ = 0;
  242.                while(_loc2_ < _loc6_.length && !_loc4_)
  243.                {
  244.                   if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
  245.                   {
  246.                      _loc4_ = true;
  247.                   }
  248.                   _loc2_ = _loc2_ + 1;
  249.                }
  250.                if(!_loc4_)
  251.                {
  252.                   _loc6_.push(_loc3_[_loc1_]._territory);
  253.                }
  254.             }
  255.             _loc1_ = _loc1_ + 1;
  256.          }
  257.          _loc7_ = _loc7_ + 1;
  258.       }
  259.       return _loc6_.length;
  260.    }
  261.    function freeNeighboursArr(mc)
  262.    {
  263.       var _loc3_ = new Array();
  264.       var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL];
  265.       var _loc1_ = 0;
  266.       while(_loc1_ < _loc2_.length)
  267.       {
  268.          if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
  269.          {
  270.             _loc3_.push(_loc2_[_loc1_]);
  271.          }
  272.          _loc1_ = _loc1_ + 1;
  273.       }
  274.       return _loc3_;
  275.    }
  276.    function freeNeighboursArr2(mc)
  277.    {
  278.       var _loc4_ = new Array();
  279.       var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL,mc.L,mc.R,mc.L,mc.R];
  280.       var _loc1_ = 0;
  281.       while(_loc1_ < _loc2_.length)
  282.       {
  283.          if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
  284.          {
  285.             _loc4_.push(_loc2_[_loc1_]);
  286.          }
  287.          _loc1_ = _loc1_ + 1;
  288.       }
  289.       return _loc4_;
  290.    }
  291.    function burnTerritory(terrArr)
  292.    {
  293.       var _loc1_ = 0;
  294.       while(_loc1_ < terrArr.length)
  295.       {
  296.          terrArr[_loc1_]._inTerritory = true;
  297.          _loc1_ = _loc1_ + 1;
  298.       }
  299.    }
  300.    function makeBorder(terrObj, r)
  301.    {
  302.       var _loc7_ = this.BORDER_SIZE;
  303.       var _loc6_ = this.BORDER_COLOR;
  304.       var _loc11_ = new Array();
  305.       var _loc10_ = 0;
  306.       while(_loc10_ < terrObj.arr.length)
  307.       {
  308.          var _loc8_ = terrObj.arr[_loc10_];
  309.          var _loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
  310.          var _loc5_ = 0;
  311.          while(_loc5_ < _loc9_.length)
  312.          {
  313.             if(_loc9_[_loc5_]._territory != terrObj && !_loc8_._onBorder)
  314.             {
  315.                _loc8_._onBorder = true;
  316.                _loc11_.push(_loc8_);
  317.             }
  318.             _loc5_ = _loc5_ + 1;
  319.          }
  320.          _loc10_ = _loc10_ + 1;
  321.       }
  322.       var _loc2_ = this.ROOT_MC.createEmptyMovieClip("border" + this.counter,this.counter++);
  323.       _loc2_._x = _loc11_[0]._x;
  324.       _loc2_._y = _loc11_[0]._y;
  325.       terrObj.border = _loc2_;
  326.       this.rubbish_arr.push(_loc2_);
  327.       _loc10_ = 0;
  328.       while(_loc10_ < _loc11_.length)
  329.       {
  330.          _loc8_ = _loc11_[_loc10_];
  331.          var _loc4_ = _loc8_._x - _loc2_._x;
  332.          var _loc3_ = _loc8_._y - _loc2_._y;
  333.          _loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
  334.          _loc5_ = 0;
  335.          while(_loc5_ < _loc9_.length)
  336.          {
  337.             if(_loc9_[_loc5_]._territory != _loc8_._territory || _loc9_[_loc5_] == undefined)
  338.             {
  339.                switch(_loc5_)
  340.                {
  341.                   case 5:
  342.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  343.                      _loc2_.moveTo(_loc4_ + this.HEX.BL.x,_loc3_ + this.HEX.BL.y);
  344.                      _loc2_.lineTo(_loc4_ + this.HEX.B.x,_loc3_ + this.HEX.B.y);
  345.                      break;
  346.                   case 1:
  347.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  348.                      _loc2_.moveTo(_loc4_ + this.HEX.BL.x,_loc3_ + this.HEX.BL.y);
  349.                      _loc2_.lineTo(_loc4_ + this.HEX.TL.x,_loc3_ + this.HEX.TL.y);
  350.                      break;
  351.                   case 3:
  352.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  353.                      _loc2_.moveTo(_loc4_ + this.HEX.BR.x,_loc3_ + this.HEX.BR.y);
  354.                      _loc2_.lineTo(_loc4_ + this.HEX.B.x,_loc3_ + this.HEX.B.y);
  355.                      break;
  356.                   case 2:
  357.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  358.                      _loc2_.moveTo(_loc4_ + this.HEX.TR.x,_loc3_ + this.HEX.TR.y);
  359.                      _loc2_.lineTo(_loc4_ + this.HEX.T.x,_loc3_ + this.HEX.T.y);
  360.                      break;
  361.                   case 4:
  362.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  363.                      _loc2_.moveTo(_loc4_ + this.HEX.TR.x,_loc3_ + this.HEX.TR.y);
  364.                      _loc2_.lineTo(_loc4_ + this.HEX.BR.x,_loc3_ + this.HEX.BR.y);
  365.                      break;
  366.                   case 0:
  367.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  368.                      _loc2_.moveTo(_loc4_ + this.HEX.TL.x,_loc3_ + this.HEX.TL.y);
  369.                      _loc2_.lineTo(_loc4_ + this.HEX.T.x,_loc3_ + this.HEX.T.y);
  370.                }
  371.             }
  372.             _loc5_ = _loc5_ + 1;
  373.          }
  374.          _loc10_ = _loc10_ + 1;
  375.       }
  376.    }
  377.    function randomUnits(players)
  378.    {
  379.       var _loc12_ = Math.round(this.AV_UNITS_PER_TERRITORY * this.TERRITORIES_ARR.length);
  380.       var _loc9_ = new Array();
  381.       var _loc10_ = new Array();
  382.       var _loc5_ = 0;
  383.       while(_loc5_ < players)
  384.       {
  385.          _loc9_.push(Math.floor(_loc12_ / players));
  386.          _loc5_ = _loc5_ + 1;
  387.       }
  388.       _loc5_ = 0;
  389.       while(_loc5_ < _loc12_ - Math.floor(_loc12_ / players) * players)
  390.       {
  391.          _loc9_[_loc9_.length - 1 - _loc5_] += 1;
  392.          _loc5_ = _loc5_ + 1;
  393.       }
  394.       var _loc15_ = Math.floor(this.TERRITORIES_ARR.length / players);
  395.       var _loc14_ = this.TERRITORIES_ARR.length - players * Math.floor(this.TERRITORIES_ARR.length / players);
  396.       _loc5_ = 0;
  397.       while(_loc5_ < players)
  398.       {
  399.          _loc10_.push(_loc15_);
  400.          _loc5_ = _loc5_ + 1;
  401.       }
  402.       _loc5_ = 0;
  403.       while(_loc5_ < _loc14_)
  404.       {
  405.          _loc10_[_loc10_.length - 1 - _loc5_] += 1;
  406.          _loc5_ = _loc5_ + 1;
  407.       }
  408.       var _loc13_ = new Array();
  409.       var _loc11_ = new Array();
  410.       _loc5_ = 0;
  411.       while(_loc5_ < players)
  412.       {
  413.          var _loc4_ = _loc9_[_loc5_];
  414.          var _loc7_ = _loc10_[_loc5_];
  415.          var _loc8_ = new Array();
  416.          var _loc3_ = 0;
  417.          while(_loc3_ < _loc7_)
  418.          {
  419.             var _loc2_ = 0;
  420.             while(_loc2_ > 8 || _loc2_ < 1)
  421.             {
  422.                _loc2_ = this.random2(Math.floor(_loc4_ / 2) - 1) + 1;
  423.             }
  424.             if(_loc3_ == _loc7_ - 1)
  425.             {
  426.                _loc2_ = _loc4_;
  427.                if(_loc2_ < 1)
  428.                {
  429.                   _loc2_ = 1;
  430.                }
  431.             }
  432.             _loc8_.push(_loc2_);
  433.             _loc4_ -= _loc2_;
  434.             _loc3_ = _loc3_ + 1;
  435.          }
  436.          _loc11_.push(0);
  437.          _loc13_.push(_loc8_);
  438.          _loc5_ = _loc5_ + 1;
  439.       }
  440.       _loc5_ = 0;
  441.       while(_loc5_ < this.TERRITORIES_ARR.length)
  442.       {
  443.          this.TERRITORIES_ARR[_loc5_].unitsNO = _loc13_[this.TERRITORIES_ARR[_loc5_].player - 1][_loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]];
  444.          _loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]++;
  445.          _loc5_ = _loc5_ + 1;
  446.       }
  447.    }
  448.    function territoryA(terr)
  449.    {
  450.       this.CHOSEN_TERR_A = terr;
  451.       this.CHOSEN_TERR_B = undefined;
  452.       this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_ACTIVE_COLOR);
  453.       this.territoryMaxDepth(this.CHOSEN_TERR_A);
  454.    }
  455.    function territoryB(terr)
  456.    {
  457.       this.CHOSEN_TERR_B = terr;
  458.       this.colorMC(this.CHOSEN_TERR_B.border,this.BORDER_ACTIVE_COLOR);
  459.       var _loc2_ = 0;
  460.       while(_loc2_ < this.TERRITORIES_ARR.length)
  461.       {
  462.          if(this.TERRITORIES_ARR[_loc2_].border.getDepth() == this.CHOSEN_TERR_A.border.getDepth() - 1)
  463.          {
  464.             this.CHOSEN_TERR_B.border.swapDepths(this.TERRITORIES_ARR[_loc2_].border);
  465.             _loc2_ = this.TERRITORIES_ARR.length;
  466.          }
  467.          _loc2_ = _loc2_ + 1;
  468.       }
  469.    }
  470.    function territoryMaxDepth(terrObj)
  471.    {
  472.       var _loc6_ = this.TERRITORIES_ARR[0].border.getDepth();
  473.       var _loc2_ = new Array();
  474.       var _loc5_ = 0;
  475.       while(_loc5_ < this.TERRITORIES_ARR.length)
  476.       {
  477.          if(this.TERRITORIES_ARR[_loc5_].border.getDepth() < _loc6_)
  478.          {
  479.             _loc6_ = this.TERRITORIES_ARR[_loc5_].border.getDepth();
  480.          }
  481.          _loc2_.push(this.TERRITORIES_ARR[_loc5_].border);
  482.          this.TERRITORIES_ARR[_loc5_].border.swapDepths(_loc6_ + 10 + this.TERRITORIES_ARR.length + _loc5_);
  483.          _loc5_ = _loc5_ + 1;
  484.       }
  485.       _loc5_ = 0;
  486.       while(_loc5_ < _loc2_.length)
  487.       {
  488.          var _loc3_ = _loc2_.length - 1;
  489.          while(_loc3_ > _loc5_)
  490.          {
  491.             if(_loc2_[_loc3_ - 1].getDepth() > _loc2_[_loc3_].getDepth())
  492.             {
  493.                var _loc4_ = _loc2_[_loc3_];
  494.                _loc2_[_loc3_] = _loc2_[_loc3_ - 1];
  495.                _loc2_[_loc3_ - 1] = _loc4_;
  496.             }
  497.             _loc3_ = _loc3_ - 1;
  498.          }
  499.          _loc5_ = _loc5_ + 1;
  500.       }
  501.       _loc5_ = 0;
  502.       while(_loc5_ < _loc2_.length)
  503.       {
  504.          if(_loc2_[_loc5_] == terrObj.border)
  505.          {
  506.             _loc2_.splice(_loc5_,1);
  507.          }
  508.          _loc5_ = _loc5_ + 1;
  509.       }
  510.       _loc2_.push(terrObj.border);
  511.       _loc5_ = 0;
  512.       while(_loc5_ < _loc2_.length)
  513.       {
  514.          _loc2_[_loc5_].swapDepths(_loc6_ + _loc5_);
  515.          _loc5_ = _loc5_ + 1;
  516.       }
  517.    }
  518.    function resetTerritory(terr)
  519.    {
  520.       if(this.CHOSEN_TERR_B == terr)
  521.       {
  522.          this.CHOSEN_TERR_B = undefined;
  523.       }
  524.       if(this.CHOSEN_TERR_A == terr)
  525.       {
  526.          this.CHOSEN_TERR_A = undefined;
  527.       }
  528.       this.markTerritory(terr,terr.player,0);
  529.    }
  530.    function unMarkIfMarked()
  531.    {
  532.       this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_COLOR);
  533.       this.deselectAll();
  534.    }
  535.    function selectA()
  536.    {
  537.       if(!this.GAME_CLASS.isGameFinished())
  538.       {
  539.          var root = this;
  540.          var _loc4_ = 0;
  541.          while(_loc4_ < this.TERRITORIES_ARR.length)
  542.          {
  543.             var _loc6_ = false;
  544.             var _loc7_ = this.neighboursAreasArr(this.TERRITORIES_ARR[_loc4_].arr);
  545.             var _loc5_ = 0;
  546.             while(_loc5_ < _loc7_.length && !_loc6_)
  547.             {
  548.                if(_loc7_[_loc5_].player != this.TERRITORIES_ARR[_loc4_].player)
  549.                {
  550.                   _loc6_ = true;
  551.                }
  552.                _loc5_ = _loc5_ + 1;
  553.             }
  554.             if(_loc6_)
  555.             {
  556.                _loc5_ = 0;
  557.                while(_loc5_ < this.TERRITORIES_ARR[_loc4_].arr.length)
  558.                {
  559.                   var _loc3_ = this.TERRITORIES_ARR[_loc4_].arr[_loc5_];
  560.                   if(_loc3_._territory.player == 1 && _loc3_._territory.unitsNO > 1)
  561.                   {
  562.                      _loc3_.onRelease = function()
  563.                      {
  564.                         _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  565.                         if(this._territory == root.CHOSEN_TERR_A)
  566.                         {
  567.                            root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
  568.                            root.lightOffTerritory(root.CHOSEN_TERR_A);
  569.                            root.deselectB();
  570.                            root.CHOSEN_TERR_A = undefined;
  571.                         }
  572.                         else
  573.                         {
  574.                            root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
  575.                            root.lightOffTerritory(root.CHOSEN_TERR_A);
  576.                            root.deselectB();
  577.                            root.territoryA(this._territory);
  578.                            root.lightOffTerritory(this._territory);
  579.                            root.selectB();
  580.                         }
  581.                      };
  582.                      _loc3_.onRollOver = function()
  583.                      {
  584.                         if(this._territory != root.CHOSEN_TERR_A)
  585.                         {
  586.                            root.lightOnTerritory(this._territory);
  587.                         }
  588.                      };
  589.                      _loc3_.onRollOut = _loc3_.onReleaseOutside = function()
  590.                      {
  591.                         if(this._territory != root.CHOSEN_TERR_A)
  592.                         {
  593.                            root.lightOffTerritory(this._territory);
  594.                         }
  595.                      };
  596.                   }
  597.                   _loc5_ = _loc5_ + 1;
  598.                }
  599.             }
  600.             _loc4_ = _loc4_ + 1;
  601.          }
  602.       }
  603.    }
  604.    function selectB()
  605.    {
  606.       this.findAneighbours();
  607.       var root = this;
  608.       var _loc4_ = 0;
  609.       while(_loc4_ < this.TERR_A_NArr.length)
  610.       {
  611.          if(this.TERR_A_NArr[_loc4_].player != 1)
  612.          {
  613.             var _loc3_ = 0;
  614.             while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
  615.             {
  616.                var _loc5_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
  617.                _loc5_.onRelease = function()
  618.                {
  619.                   _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  620.                   root.territoryB(this._territory);
  621.                   root.fightAB();
  622.                   root.deselectAll();
  623.                };
  624.                _loc3_ = _loc3_ + 1;
  625.             }
  626.          }
  627.          _loc4_ = _loc4_ + 1;
  628.       }
  629.    }
  630.    function deselectB()
  631.    {
  632.       this.findAneighbours();
  633.       var _loc5_ = this;
  634.       var _loc3_ = 0;
  635.       while(_loc3_ < this.TERR_A_NArr.length)
  636.       {
  637.          if(this.TERR_A_NArr[_loc3_].player != 1)
  638.          {
  639.             var _loc2_ = 0;
  640.             while(_loc2_ < this.TERR_A_NArr[_loc3_].arr.length)
  641.             {
  642.                var _loc4_ = this.TERR_A_NArr[_loc3_].arr[_loc2_];
  643.                delete _loc4_.onRelease;
  644.                _loc2_ = _loc2_ + 1;
  645.             }
  646.          }
  647.          _loc3_ = _loc3_ + 1;
  648.       }
  649.    }
  650.    function deselectA()
  651.    {
  652.       var _loc5_ = this;
  653.       var _loc4_ = 0;
  654.       while(_loc4_ < this.TERR_A_NArr.length)
  655.       {
  656.          if(this.TERR_A_NArr[_loc4_].player == 1)
  657.          {
  658.             var _loc3_ = 0;
  659.             while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
  660.             {
  661.                var _loc2_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
  662.                delete _loc2_.onRollOut;
  663.                delete _loc2_.onReleaseOutside;
  664.                delete _loc2_.onRollOver;
  665.                delete _loc2_.onRelease;
  666.                _loc3_ = _loc3_ + 1;
  667.             }
  668.          }
  669.          _loc4_ = _loc4_ + 1;
  670.       }
  671.    }
  672.    function deselectAll()
  673.    {
  674.       var _loc3_ = 0;
  675.       while(_loc3_ < this.TERRITORIES_ARR.length)
  676.       {
  677.          var _loc2_ = 0;
  678.          while(_loc2_ < this.TERRITORIES_ARR[_loc3_].arr.length)
  679.          {
  680.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOver;
  681.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOut;
  682.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onReleaseOutside;
  683.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRelease;
  684.             _loc2_ = _loc2_ + 1;
  685.          }
  686.          _loc3_ = _loc3_ + 1;
  687.       }
  688.    }
  689.    function findAneighbours()
  690.    {
  691.       this.TERR_A_NArr = new Array();
  692.       var _loc8_ = this.CHOSEN_TERR_A.arr;
  693.       var _loc7_ = 0;
  694.       while(_loc7_ < _loc8_.length)
  695.       {
  696.          var _loc6_ = _loc8_[_loc7_];
  697.          var _loc4_ = [_loc6_.TL,_loc6_.L,_loc6_.TR,_loc6_.BR,_loc6_.R,_loc6_.BL];
  698.          var _loc2_ = 0;
  699.          while(_loc2_ < _loc4_.length)
  700.          {
  701.             if(_loc4_[_loc2_]._territory != _loc6_._territory && _loc4_[_loc2_]._territory != undefined)
  702.             {
  703.                var _loc5_ = false;
  704.                var _loc3_ = 0;
  705.                while(_loc3_ < this.TERR_A_NArr.length && !_loc5_)
  706.                {
  707.                   if(this.TERR_A_NArr[_loc3_] == _loc4_[_loc2_]._territory)
  708.                   {
  709.                      _loc5_ = true;
  710.                   }
  711.                   _loc3_ = _loc3_ + 1;
  712.                }
  713.                if(!_loc5_)
  714.                {
  715.                   this.TERR_A_NArr.push(_loc4_[_loc2_]._territory);
  716.                }
  717.             }
  718.             _loc2_ = _loc2_ + 1;
  719.          }
  720.          _loc7_ = _loc7_ + 1;
  721.       }
  722.    }
  723.    function neighboursAreasArr(terrArr)
  724.    {
  725.       var _loc6_ = new Array();
  726.       var _loc7_ = 0;
  727.       while(_loc7_ < terrArr.length)
  728.       {
  729.          var _loc5_ = terrArr[_loc7_];
  730.          var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
  731.          var _loc1_ = 0;
  732.          while(_loc1_ < _loc3_.length)
  733.          {
  734.             if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
  735.             {
  736.                var _loc4_ = false;
  737.                var _loc2_ = 0;
  738.                while(_loc2_ < _loc6_.length && !_loc4_)
  739.                {
  740.                   if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
  741.                   {
  742.                      _loc4_ = true;
  743.                   }
  744.                   _loc2_ = _loc2_ + 1;
  745.                }
  746.                if(!_loc4_)
  747.                {
  748.                   _loc6_.push(_loc3_[_loc1_]._territory);
  749.                }
  750.             }
  751.             _loc1_ = _loc1_ + 1;
  752.          }
  753.          _loc7_ = _loc7_ + 1;
  754.       }
  755.       return _loc6_;
  756.    }
  757.    function lightOnTerritory(terrObj)
  758.    {
  759.       var _loc1_ = 0;
  760.       while(_loc1_ < terrObj.arr.length)
  761.       {
  762.          terrObj.arr[_loc1_]._alpha = 70;
  763.          _loc1_ = _loc1_ + 1;
  764.       }
  765.    }
  766.    function lightOffTerritory(terrObj)
  767.    {
  768.       var _loc1_ = 0;
  769.       while(_loc1_ < terrObj.arr.length)
  770.       {
  771.          terrObj.arr[_loc1_]._alpha = 100;
  772.          _loc1_ = _loc1_ + 1;
  773.       }
  774.    }
  775.    function fightAB()
  776.    {
  777.       this.GAME_CLASS.FIGHTBOX.resetWinner();
  778.       this.GAME_CLASS.FIGHTBOX.fight(this.CHOSEN_TERR_A,this.CHOSEN_TERR_B);
  779.    }
  780.    function winnerFound()
  781.    {
  782.       if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_A)
  783.       {
  784.          this.winA();
  785.          if(this.GAME_CLASS.PLAYER_MOVE == 1 && !this.GAME_CLASS.isGameFinished())
  786.          {
  787.             _global.setTimeout(mx.utils.Delegate.create(this.GAME_CLASS,this.GAME_CLASS.showBiggestArea),300);
  788.          }
  789.       }
  790.       if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_B)
  791.       {
  792.          this.winB();
  793.       }
  794.       var _loc4_ = new Array();
  795.       var _loc3_ = 1;
  796.       while(_loc3_ <= this.GAME_CLASS.PLAYERS_NO)
  797.       {
  798.          _loc4_.push(this.GAME_CLASS.unitsToAdd(_loc3_));
  799.          _loc3_ = _loc3_ + 1;
  800.       }
  801.       this.GAME_CLASS.UNITS_LIST.refreshList(_loc4_,this.TERRITORIES_ARR);
  802.    }
  803.    function winA()
  804.    {
  805.       this.markTerritory(this.CHOSEN_TERR_B,this.CHOSEN_TERR_A.player,0);
  806.       this.CHOSEN_TERR_B.unitsNO = this.CHOSEN_TERR_A.unitsNO - 1;
  807.       this.CHOSEN_TERR_A.unitsNO = 1;
  808.       this.CHOSEN_TERR_B.army = this.CHOSEN_TERR_A.army;
  809.       this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
  810.       this.CHOSEN_TERR_B.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_B.unitsNO,this.CHOSEN_TERR_B.player);
  811.       this.resetTerritory(this.CHOSEN_TERR_A);
  812.       this.resetTerritory(this.CHOSEN_TERR_B);
  813.       this.deselectAll();
  814.    }
  815.    function winB()
  816.    {
  817.       this.CHOSEN_TERR_A.unitsNO = 1;
  818.       this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
  819.       this.resetTerritory(this.CHOSEN_TERR_A);
  820.       this.resetTerritory(this.CHOSEN_TERR_B);
  821.       this.deselectAll();
  822.    }
  823.    function colorMC(mc, cl)
  824.    {
  825.       var _loc1_ = new Color(mc);
  826.       _loc1_.setRGB(cl);
  827.    }
  828.    function rad2deg(rad)
  829.    {
  830.       return rad * 180 / 3.141592653589793;
  831.    }
  832.    function deg2rad(deg)
  833.    {
  834.       return deg * 3.141592653589793 / 180;
  835.    }
  836.    function random2(z)
  837.    {
  838.       return Math.round(Math.random() * z);
  839.    }
  840.    function shuffledArray(arr)
  841.    {
  842.       var _loc5_ = 0;
  843.       while(_loc5_ < 30)
  844.       {
  845.          var _loc4_ = this.random2(arr.length - 1);
  846.          var _loc3_ = this.random2(arr.length - 1);
  847.          var _loc6_ = arr[_loc4_];
  848.          arr[_loc4_] = arr[_loc3_];
  849.          arr[_loc3_] = _loc6_;
  850.          _loc5_ = _loc5_ + 1;
  851.       }
  852.       return arr;
  853.    }
  854.    function clearAll()
  855.    {
  856.       var _loc2_ = 0;
  857.       while(_loc2_ < this.rubbish_arr.length)
  858.       {
  859.          this.rubbish_arr[_loc2_].removeMovieClip();
  860.          _loc2_ = _loc2_ + 1;
  861.       }
  862.    }
  863. }
  864.